package com.kfm.filter;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import java.io.IOException;

//@WebFilter(urlPatterns = "/hello", dispatcherTypes = {DispatcherType.REQUEST, DispatcherType.FORWARD})
public class HelloFilter implements Filter {

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        System.out.println("HelloFilter --> init");
    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        System.out.println("HelloFilter --> doFilter  start");

        // 如果可以访问资源, 则执行下边的代码
        filterChain.doFilter(servletRequest, servletResponse);


        System.out.println("HelloFilter --> doFilter  end");
    }

    @Override
    public void destroy() {
        System.out.println("HelloFilter --> destroy");
    }
}
